package main

import "fmt"

type Sender interface {
	Send(to, msg string) error
	SendAll(tos []string, msg string) error
}

type EmailSender struct {
	addr           string
	port           int
	user, password string
}

func NewEmailSender(addr string, port int, user, password string) EmailSender {
	return EmailSender{addr, port, user, password}
}

//	接收者为值对象
func (sender EmailSender) Send(to, msg string) error {
	fmt.Printf("发送邮件给：%s, 内容: %s\n", to, msg)
	return nil
}

//	接收者为值对象
func (sender EmailSender) SendAll(tos []string, msg string) error {
	for _, to := range tos {
		fmt.Printf("发送邮件给: %s,内容: %s\n", to, msg)
	}
	return nil
}

func main() {
	var sender Sender
	fmt.Printf("%T: %v\n", sender, sender)

	//	赋值sender对象为NewEmailSender值对象
	var sender01 Sender = EmailSender{
		addr:     "smtp.qq.com",
		port:     465,
		user:     "kk",
		password: "12345",
	}
	fmt.Printf("%T: %v\n", sender01, sender01)
	sender01.Send("aa@qq.com", "i am aa")
	sender01.SendAll([]string{"aa@qq.com", "bb@qq.com"}, "good night")
}
